package me.android.library.utils.android;

import android.app.Activity;
import android.content.Context;

import androidx.fragment.app.Fragment;

import lombok.experimental.UtilityClass;
import lombok.extern.slf4j.Slf4j;
import pub.devrel.easypermissions.EasyPermissions;
import pub.devrel.easypermissions.PermissionRequest;

@Slf4j
@UtilityClass
public class PermissionUtil implements Permissions {

    final int THEME = android.R.style.Theme_DeviceDefault_Light_Dialog;

    /**
     * 检查是否拥有指定权限
     */
    public boolean hasPermissions(Context context, String... permissions) {
        return EasyPermissions.hasPermissions(context, permissions);
    }

    public void requestPermissions(Activity activity,int requestCode, String... permissions) {
        PermissionRequest request = new PermissionRequest.Builder(activity, requestCode, permissions)
                .setRationale("申请相关权限")
                .setPositiveButtonText("确定")
                .setNegativeButtonText("取消")
                .setTheme(THEME)
                .build();
        EasyPermissions.requestPermissions(request);
    }

    public void requestPermissions(Fragment fragment, int requestCode, String... permissions) {
        PermissionRequest request = new PermissionRequest.Builder(fragment, requestCode, permissions)
                .setRationale("申请相关权限")
                .setPositiveButtonText("确定")
                .setNegativeButtonText("取消")
                .setTheme(THEME)
                .build();
        EasyPermissions.requestPermissions(request);
    }

}